﻿package mortal.game.view.copy.GroupTowerCopy.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.GroupTowerCopy.data.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.guildNew.*;
    import mortal.mvc.core.*;

    public class GroupTowerCopyInfoPanel extends CopyInfoPanelBase
    {
        protected var _bg:GImageBitmap;
        protected var _curGuan:GTextFiled;
        protected var _time:BitmapNumberText;
        protected var _timeTile:GBitmap;
        protected var _curLevelTitle:GBitmap;
        protected var _line1:ScaleBitmap;
        protected var _bossName:GTextFiled;
        protected var _rwTitle:GBitmap;
        protected var _copyRwList:CellsGridSprite;
        protected var _line2:ScaleBitmap;
        protected var _myRwTitle:GBitmap;
        protected var _myExp:GTextFiled;
        protected var _downItems:CellsGridSprite;
        protected var _listTBg:ScaleBitmap;
        protected var _infoTitle:GBitmap;
        protected var _gaiDes:GTextFiled;
        protected var _tip1:GTextFiled;
        protected var _tip2:GTextFiled;
        protected var _tipTi:GTextFiled;
        protected var _quiBtn:GLoadingButton;
        protected var _rentBtn:GLoadingButton;
        protected var _secView:SecTimerView;
        private var _isResload:Boolean = false;
        private var _info:SGroupTowerMsg;
        private static var _instance:GroupTowerCopyInfoPanel;

        public function GroupTowerCopyInfoPanel()
        {
            super(ImagesConst.copyInfoPanelTitle_groupTower, 250, 535);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._secView = new SecTimerView();
            this._secView.addEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            LoaderHelp.addResCallBack(ResFileConst.groupTower, this.onReload);
            return;
        }// end function

        private function onReload() : void
        {
            this._isResload = true;
            this._bg = UIFactory.gImageBitmap(ImagesConst.GroupTowerInfoBgg, 0, 0, _bodySprite);
            this._curGuan = UIFactory.gTextField("10/" + GroupTowerCopyUtil.TotalLevel, 79, 148, 100, 30, _bodySprite, GlobalStyle.textFormatHuang2.setSize(15));
            this._time = UIFactory.bitmapNumberText(124, 74, "ChallengeTimerNum.png", 35, 48, 0, _bodySprite, 10, 1);
            this._time.text = "15(00";
            this._timeTile = UIFactory.gBitmap(ImagesConst.GroupTowerCownTime, 17, 49, _bodySprite);
            this._curLevelTitle = UIFactory.gBitmap(ImagesConst.GroupTowerCurLevel, 12, 152, _bodySprite);
            this._line1 = UIFactory.bg(5, 185, 227, 1, _bodySprite, ImagesConst.SplitLine);
            this._bossName = UIFactory.gTextField("", 163, 148, 102, 25, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13));
            this._rwTitle = UIFactory.gBitmap(ImagesConst.GroupTowerRewTitle, 16, 202, _bodySprite);
            this._copyRwList = UIFactory.getUICompoment(CellsGridSprite);
            this._copyRwList.colNum = 4;
            this._copyRwList.vCellWid = 42;
            this._copyRwList.hCellWid = 100;
            this._copyRwList.genCellFun = this.genCell;
            this._copyRwList.genCells(4);
            this._copyRwList.x = 53;
            this._copyRwList.y = 200;
            _bodySprite.addChild(this._copyRwList);
            this._line2 = UIFactory.bg(11, 252, 229, 1, _bodySprite, ImagesConst.SplitLine);
            this._myRwTitle = UIFactory.gBitmap(ImagesConst.GroupTowerMyRewd, 12, 265, _bodySprite);
            this._myExp = UIFactory.gTextField("", 88, 261, 120, 25, _bodySprite, GlobalStyle.textFormatHuang2.setSize(16));
            this._downItems = UIFactory.getUICompoment(CellsGridSprite);
            this._downItems.colNum = 4;
            this._downItems.vCellWid = 43;
            this._downItems.hCellWid = 100;
            this._downItems.genCellFun = this.genCell;
            this._downItems.genCells(4);
            this._downItems.x = 49;
            this._downItems.y = 298;
            _bodySprite.addChild(this._downItems);
            this._listTBg = UIFactory.bg(9, 357, 237, 23, _bodySprite, ImagesConst.RegionTitleBg);
            this._infoTitle = UIFactory.gBitmap(ImagesConst.GroupTowerDetail, 69, 18, _bodySprite);
            this._gaiDes = UIFactory.gTextField("" + Language.getString(70918), 126, 148, 40, 25, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13));
            this._tip1 = UIFactory.gTextField("" + Language.getString(70919), 28, 424, 100, 20, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215));
            this._tip2 = UIFactory.gTextField("" + Language.getString(70920), 47, 445, 210, 20, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215));
            this._tipTi = UIFactory.gTextField("" + Language.getString(70921), 83, 358, 100, 20, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215));
            this._quiBtn = UIFactory.gLoadingButton(ImagesConst.ExitCopyBtn_upSkin, 78, 471, 103, 38, _bodySprite);
            this._quiBtn.label = "";
            this._rentBtn = UIFactory.gLoadingButton(ImagesConst.GuildNewMercenaryRentBtn_upSkin, 88, 384, 90, 45, _bodySprite);
            this._rentBtn.label = "";
            this.updateInfo(this._info);
            this._rentBtn.visible = LevelCheckUtil.isLevelEnougth(LevelCheckUtil.mercenary);
            this._rentBtn.configEventListener(MouseEvent.CLICK, this.onRentHd);
            this._quiBtn.configEventListener(MouseEvent.CLICK, this.onQuickHd);
            return;
        }// end function

        private function genCell() : BaseItem
        {
            var _loc_1:* = UIFactory.getUICompoment(BaseItem);
            _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._isResload == false)
            {
                return;
            }
            this._isResload = false;
            this._bg = null;
            this._curGuan = null;
            this._time = null;
            this._timeTile = null;
            this._curLevelTitle = null;
            this._line1 = null;
            this._bossName = null;
            this._rwTitle = null;
            this._copyRwList = null;
            this._line2 = null;
            this._myRwTitle = null;
            this._myExp = null;
            this._downItems = null;
            this._listTBg = null;
            this._infoTitle = null;
            this._gaiDes = null;
            this._tip1 = null;
            this._tip2 = null;
            this._tipTi = null;
            this._quiBtn = null;
            this._rentBtn = null;
            this._secView = null;
            this._info = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateInfo(param1:SGroupTowerMsg) : void
        {
            this._info = param1;
            if (this._isResload == false || this._info == null)
            {
                return;
            }
            this.updateGuanTxt();
            if (!GroupTowerCopyUtil.isStarTime)
            {
                this._secView.stop();
            }
            else
            {
                this._secView.setLeftTime(param1.surplusSeconds);
            }
            return;
        }// end function

        public function updateGuanTxt() : void
        {
            if (this._isResload == false || this._info == null)
            {
                return;
            }
            var _loc_1:* = GroupTowerCopyUtil.getCurMapLevel(this._info.copyCode);
            this._curGuan.text = "" + _loc_1 + "/" + GroupTowerCopyUtil.TotalLevel;
            this.updateCopyInfo(_loc_1);
            return;
        }// end function

        private function updateCopyInfo(param1:int) : void
        {
            var _loc_9:String = null;
            var _loc_10:ItemData = null;
            var _loc_11:BaseItem = null;
            var _loc_12:int = 0;
            var _loc_13:int = 0;
            var _loc_14:BaseItem = null;
            var _loc_15:ItemData = null;
            if (this._info == null)
            {
                return;
            }
            var _loc_2:* = this._info.copyCode;
            var _loc_3:* = GroupTowerConfig.instance.getInfoByCodeAndLvl(this._info.copyCode, param1);
            if (_loc_3 == null)
            {
                return;
            }
            var _loc_4:* = parseInt(_loc_3.passCondition);
            var _loc_5:* = BossConfig.instance.getInfoByCode(_loc_4);
            this._bossName.text = "" + _loc_5.name;
            var _loc_6:* = RewardCfgUtil.getItemDatasByStr(_loc_3.rewards);
            this._copyRwList.genCells(4);
            var _loc_7:int = 0;
            while (_loc_7 < this._copyRwList.cellArr.length && _loc_7 < _loc_6.length)
            {
                
                _loc_10 = _loc_6[_loc_7];
                _loc_11 = this._copyRwList.cellArr[_loc_7];
                _loc_11.itemData = _loc_10;
                _loc_7++;
            }
            this._myExp.text = Language.getString(70922) + this._info.exp;
            var _loc_8:int = 0;
            this._downItems.genCells(4);
            for (_loc_9 in this._info.rewards)
            {
                
                if (_loc_8 >= this._downItems.cellArr.length)
                {
                    break;
                }
                _loc_12 = parseInt(_loc_9);
                _loc_13 = this._info.rewards[_loc_9];
                _loc_14 = this._downItems.cellArr[_loc_8];
                _loc_15 = new ItemData(_loc_12);
                _loc_15.itemAmount = _loc_13;
                _loc_14.itemData = _loc_15;
                _loc_8++;
            }
            return;
        }// end function

        public function updateHurtList(param1:Array) : void
        {
            return;
        }// end function

        protected function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.mm();
            var _loc_3:* = this._secView.secTimerViewData.ss();
            this._time.text = _loc_2 + "(" + _loc_3;
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            return;
        }// end function

        private function onRentHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildNewMercenaryOpen, GuildNewModule.Mercenary));
            return;
        }// end function

        private function onQuickHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            return;
        }// end function

        public static function get instance() : GroupTowerCopyInfoPanel
        {
            if (_instance == null)
            {
                _instance = new GroupTowerCopyInfoPanel;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
